﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取表单中文本框的个数</title>
    <script type="text/javascript" language="JavaScript">
        function checkform(){
            let icount = 0;
            let frm = document.getElementById("form1").getElementsByTagName("input");
            // 获取窗体中所有的input元素
            for(var i = 0;i< frm.length;i++){
                if(frm[i].type === "text"){
                    icount++;
                }
            }
            alert("总共有"+icount+"个文本框");
        }
        
    </script>
</head>
<body>
<form action="" name="dd" method="get" id="form1">
    <input name="" type="text">
    <input name="" type="text">
    <input name="" type="text">
    <input name="提交" value="提交" type="submit" onclick="checkform()">
</form>
</body>
</html>